package com.sean.util;

import java.lang.reflect.Type;
import java.util.HashMap;
import java.util.Map;

import com.google.gson.Gson;

public class JsonUtils {
	
	@SuppressWarnings("unchecked")
	public static Map<String, Object> toObject(String jsonStr) {
		return (Map<String, Object>)(new Gson()).fromJson(jsonStr, HashMap.class);
	}
	
	public static <T> T toObject(String jsonStr, Class<T> classOfT) {
		return (new Gson()).fromJson(jsonStr, classOfT);
	}
	
	public static String toJsonStr(Object jsonObj) {
		return (new Gson()).toJson(jsonObj);
	}
	
	@SuppressWarnings("unchecked") 
	public static <T> T toObject(String jsonStr, Type typeOfT) {
		return (T)(new Gson()).fromJson(jsonStr, typeOfT);
	}
}
